// page/index/information.js
var app = getApp();
var datas = require('../../utils/data');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date:'2005',
    index: 7,
    hasindex:false,
    information:{
      name: "",
      date: "",
      filler: "",
      sex: "",
      grade: "",
      levelsF: "",
      levelsM: "",
      professionsF: '',
      professionsM: '',
      persons: [],
    },
    name:"",
    sex:[
      { name: 'USA', value: '男' },
      { name: 'CHN', value: '女' }
    ],
    writtenBy: [
      { name: 'USA', value: '父亲' },
      { name: 'CHN', value: '母亲' },
      { name: 'CHN', value: '其他' }
    ],
    array: ['小学一年级', '小学二年级', '小学三年级', '小学四年级', '小学五年级', '小学六年级', '初中一年级', '初中二年级', '初中三年级', '高中一年级', '高中二年级', '高中三年级',],
    levelsF: datas.levels,
    levelsM: datas.levels,
    professionsF: datas.professions,
    professionsM: datas.professions,
    persons: datas.persons,
  },
  // 年级
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({ index: e.detail.value,  hasindex :true })
    var that = this;
    var information = that.data.information;
    information.grade = that.data.array[e.detail.value];
    this.setData({ information: information })
  },
  // 名字
  bindnameChange(e){
    console.log('bindnameChange 携带值为', e);
    var that =this;
    var information=that.data.information;
    information.name = e.detail.value;
    this.setData({ information: information  })
  },
  // 生日
  bindDateChange: function (e) { 
    this.setData({ date: e.detail.value })
    var that = this;
    var information = that.data.information;
    information.date = e.detail.value.substring(0, 7);  
    this.setData({ information: information }) 
  },
  // 填写人
  radioChangeWrittenBy: function (e) {
    var that = this;
    var information = that.data.information;
    information.filler = e.detail.value;
    this.setData({ information: information })
  },
  // 性别
  radioChange:function(e){
    var that = this;
    var information = that.data.information;
    information.sex = e.detail.value;
    this.setData({ information: information }) 
  },
  // 家庭成员
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value);

    var persons = this.data.persons, values = e.detail.value;
     
    var that = this;
    var information = that.data.information;
    information.persons = e.detail.value;
    this.setData({ information: information })  
  },
  // 文化水平父亲
  radioChangeLevelF: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value); 
    var levelsF = this.data.levelsF; 
    var that = this;
    var information = that.data.information;
    information.levelsF = e.detail.value;
    this.setData({  information: information })  
  },
  // 文化水平妈妈
  radioChangeLevelM: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value);
    var levelsM = this.data.levelsM;
     
    var that = this;
    var information = that.data.information;
    information.levelsM = e.detail.value;
    this.setData({  information: information })
  },
  // 职位父亲
  radioChangeprofessionsF: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value);
    var professionsF = this.data.professionsF; 
    var that = this;
    var information = that.data.information;
    information.professionsF = e.detail.value;
    this.setData({ information: information })
  },
   // 职位妈妈
  radioChangeprofessionsM: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value);
    var professionsM = this.data.professionsM;
     
    var that = this;
    var information = that.data.information;
    information.professionsM = e.detail.value;
    this.setData({ information: information })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
   add(){
     var that=this;
     var information = that.data.information;
     app.globalData.information = that.data.information;
     if (information.name != "" && information.date != "" && information.persons.length != 0 && information.filler != "" && information.sex != "" && information.grade != "" && information.levelsF != "" && information.levelsM != "" && information.professionsF != "" && information.professionsM != ""){
       wx.navigateTo({
         url: 'detail', 
       })
     }else{
       app.error("请完善信息");
     }
     
   },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})